package com.amit;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SearchBookServlet  extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//1.collect the data
		String cat=request.getParameter("category");
		if(cat.equals("Java"))
		{
			List<String> books=new ArrayList<String>();
			books.add("Learn Java");
			books.add("Master EJB");
			books.add("JSF RED BLACK");
			books.add("Master Android");
			books.add("Learn JDBC");
			books.add("Master Spring");
			books.add("Hibernate RED BLACK");
			
			HttpSession session =request.getSession();
			session.setAttribute("BOOKS", books);
			
		}
		
		else
		{
			String msg="No Books Available in Bookstore";
			request.setAttribute("MSG", msg);
		}
		
		RequestDispatcher rd=request.getRequestDispatcher("showbooks.jsp");
		rd.forward(request, response);
		
	}

}
